{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit" xmlns: xmlns:>
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form layui-form-pane" lay-filter="form">
        <div class="layui-form-item">
            <label class="layui-form-label">闸机名称</label>
            <div class="layui-input-4">
                <input type="text" name="device_name" lay-verify="required" placeholder="{:lang('pleaseEnter')}闸机名称" class="layui-input" value="{:isset($info.device_name)?$info.device_name:''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">闸机ip</label>
            <div class="layui-input-4">
                <input type="text" name="ip" lay-verify="required" placeholder="{:lang('pleaseEnter')}闸机ip" class="layui-input" value="{:isset($info.ip)?$info.ip:''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">闸机端口号</label>
            <div class="layui-input-4">
                <input type="text" name="port_number" lay-verify="required" placeholder="{:lang('pleaseEnter')}闸机端口号" class="layui-input" value="{:isset($info.port_number)?$info.port_number:''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">闸机位置</label>
            <div class="layui-input-4">
                <input type="text" name="location" lay-verify="required" placeholder="{:lang('pleaseEnter')}闸机位置" class="layui-input" value="{:isset($info.location)?$info.location:''}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
                <input type="text"  name="start_time"  class="layui-input" id="start_time" placeholder="H:m" value="{:isset($info.start_time)?$info.start_time:''}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                开始工作时间。
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-inline">
                <input type="text"  name="end_time"  class="layui-input" id="end_time" placeholder="H:m" value="{:isset($info.end_time)?$info.end_time:''}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                结束工作时间。
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">工作日</label>
            <div class="layui-input-block">
                <input type="checkbox" name="work_time" value="1" lay-skin="primary" title="周一" {:isset($info.work_time) && in_array(1,$info.work_time)?'checked':''}>
                <input type="checkbox" name="work_time" value="2" lay-skin="primary" title="周二" {:isset($info.work_time) && in_array(2,$info.work_time)?'checked':''}>
                <input type="checkbox" name="work_time" value="3" lay-skin="primary" title="周三" {:isset($info.work_time) && in_array(3,$info.work_time)?'checked':''}>
                <input type="checkbox" name="work_time" value="4" lay-skin="primary" title="周四" {:isset($info.work_time) && in_array(4,$info.work_time)?'checked':''}>
                <input type="checkbox" name="work_time" value="5" lay-skin="primary" title="周五" {:isset($info.work_time) && in_array(5,$info.work_time)?'checked':''}>
                <input type="checkbox" name="work_time" value="6" lay-skin="primary" title="周六" {:isset($info.work_time) && in_array(6,$info.work_time)?'checked':''}>
                <input type="checkbox" name="work_time" value="0" lay-skin="primary" title="周日" {:isset($info.work_time) && in_array(0,$info.work_time)?'checked':''}>
            </div>

        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="id">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('brakeMachine')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
        <input name="id" value="{:isset($info.id)?$info.id:''}" type="hidden">
    </form>

</div>
{include file="common/foot"/}

<script>
    //用于子窗体向父窗体赋值
    function setRel(rel){
        this.rel=rel;
    }

    layui.use(['form','laydate', 'layer','upload'], function () {
        var form = layui.form, layer = layui.layer,$= layui.jquery,upload = layui.upload,laydate = layui.laydate;
        $('#object').hide();
        var info = {$info|raw};
        form.val("form", info);
        form.render();

        form.on('submit(submit)', function (data) {
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var arr = new Array();
            $("input:checkbox[name='work_time']:checked").each(function(i){
                arr[i] = $(this).val();
            });
            if(arr==''){
                var d1 =  '';
            }else{
                var d1 =  JSON.stringify(arr);
            }
            data.field.work_time = d1;

            $.post("",data.field, function (res) {
                layer.close(loading);
                if (res.code > 0) {
                    layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                        location.href = res.url;
                    });
                } else {
                    layer.msg(res.msg, {time: 1800, icon: 2});
                }
            });
        });

        laydate.render({
            elem: '#start_time'
            ,type: 'time'
            ,format: 'H：m'
        });
        laydate.render({
            elem: '#end_time'
            ,type: 'time'
            ,format: 'H：m'
        });

    });

</script>